/*
 * @Author: 小花
 * @Date: 2022-05-25 15:05:58
 * @LastEditors: 小花
 * @LastEditTime: 2022-05-27 21:00:25
 * @FilePath: /permission_client/src/model/UserView.ts
 * @Description:
 */

import { ElTable, FormInstance } from 'element-plus'

/**
 * account: "110101199003071735"
avatar: null
createTime: "2022-05-21 00:00:00"
delFlag: false
email: null
id: "1527996072423587841"
password: "111"
phone: null
salt: "kfwoox"
status: false
updateBy: null
username: "系统账号"
 */

export interface IUser {
  id?: string,
  account: string,
  username: string,
  avatar: string,
  password: string,
  phone: string,
  email: string,
  status: boolean,
  roleIds: string[],
  createBy?: string,
  createTime?: string,
  updateBy?: string,
  updateTime?: string
}

export interface IUserRole {
  id?: string,
  userId: string,
  roleId: string,
}

export const EStatus = [
  { label: '正常', value: false, type: '', setStatus: '冻结' },
  { label: '冻结', value: true, type: 'danger', setStatus: '解冻' }
]

export const rules = {
  account: [
    { required: true, message: '请输入账号', trigger: 'change' },
    { min: 6, max: 32, message: '账号长度为6-32位', trigger: 'change' }
  ],
  username: [
    { required: true, message: '请输入用户名', trigger: 'change' },
    { min: 2, max: 18, message: '用户名长度为2-18位', trigger: 'change' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'change' },
    { min: 6, max: 32, message: '密码长度为6-32位', trigger: 'change' }
  ],
  roleIds: [
    { required: true, message: '请选择用户角色', trigger: 'change' }
  ],
  phone: [
    { required: true, message: '请输入电话', trigger: 'change' },
    { pattern: /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/, message: '请正确输入移动电话', trigger: 'change' }
  ],
  email: [
    { required: true, type: 'email', message: '请输入邮箱', trigger: 'change' },
    { pattern: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, message: '请正确输入邮箱', trigger: 'change' }
  ]
}

export const dialogTemplate = {
  add: { title: '添加新用户', flag: false },
  edit: { title: '编辑用户', flag: true }
}

export default class UserView {
  userList = [] as IUser[]
  userRoleList = [] as IUserRole[]
  tableSearchValue = ''
  multipleTableRef = {} as InstanceType<typeof ElTable>
  multipleSelection = [] as IUser[]
  ruleFormRef = {} as FormInstance
  dialogFormVisible = false
  form = {
    status: false
  } as IUser

  dialogTitle = {
    title: '',
    flag: false
  }

  uploadFile = {} as File

  pagination = {
    // 每页显示条目个数
    pageSize: 10,
    // 每页显示个数选择器的选项设置
    pageSizes: [10, 30, 80, 120],
    // 设置最大页码按钮数
    pagerCount: 5,
    // 当前页数
    currentPage: 1,
    // 总条目数
    total: 0
  }
}
